<?php

namespace app\admin\model\express;

use think\Model;


class Packagetrack extends Model
{

    // 表名
    protected $name = 'express_packagetrack';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'createtime_text'
    ];

    public function getCreatetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['createtime']) ? $data['createtime'] : '');
        if ($value == 0) {
            return "";
        }
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    public function track()
    {
        return $this->belongsTo(Track::class, 'track_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

}
